Extending the Business Logic Using Custom Classes |
|
A custom class is created by combining data from more than one database table and storing it in a single object. Unlike a standard class, a custom class helps in situations where data from a single database table is functionally not sufficient. This is better understood with the help of an example.
Example
There are two database tables - Order and Customer. The Order table contains the Order Number and the Date, whereas the Customer table contains the Customer's name and Address. If a class is created out of the Order table, it will contain only the Order Number and Date but not the customer details. To have details of both the Order table and the Customer table, you need to create a custom class from these two tables.
The figure above represents a custom class that contains information from both the database tables.
WS-AppServer supports creating the following types of custom classes using Object Layout:
- Pure Custom class: A pure custom class is a class that is created without using any other standard or custom class. To design this type of custom class, you need to explicitly implement read and write functionality (from database to Java, and vice-versa) for that class. For example,
<MyCompany> <Director>string</Director> <Manager>string</Manager> <Department>string</Department> <EmployeeID>i4</EmployeeID> </MyCompany>
- Derived Custom class: A derived custom class is a combination of one or more standard classes. For derived custom classes, WS-AppServer generates the read and update methods, which handle data exchange from the Java layer to the database. For more information, refer topic Derived Custom Class.
- Query-based Custom class: A query-based custom class is generated based on a SQL query created in WS-AppServer. For a detailed description, refer Creating a Query-based Custom Class.
- Inherited Custom class: A class that is inherited from another class. For example, when you create an Inherited custom class called InheritedClass that inherits another class called Categories, you get the following layout:
<class> <name>InheritedClass</name> <type>inherits</type> <inherits>Categories</inherits> <attributes xmlns="http://schemas.cordys.com/wsappserver/WSAppServerClass/1.0" xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/"/> <methods> <method cursor="false" implementation="default:GetByAttributes" soap="true" soapresult="tupleset" static="true"> <name>getInheritedClassObject</name> <return> <type occ="1">InheritedClass</type> </return> <parameters> <parameter> <name attribute="CategoryID">CategoryID</name> <type>ui2</type> </parameter> </parameters> </method> <method cursor="true" implementation="default:GetByAttributesRange" soap="true" soapresult="tupleset" static="true"> <name>getInheritedClassObjects</name> <return> <type occ="*">InheritedClass</type> </return> <parameters> <parameter> <name attribute="CategoryID">fromCategoryID</name> <type>ui2</type> </parameter> <parameter> <name attribute="CategoryID">toCategoryID</name> <type>ui2</type> </parameter> </parameters> </method> <method/> </methods> </class>
Note: Custom classes can be either flattened or nested. A flattened custom class has all its attributes at a single level. In other words, its object layout does not have a nested structure. A nested custom class has a nested structure and its object layout contains more than one custom class.